﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ToursAgencyDAL;

namespace TourAgency.Admin
{
    public partial class Destinations : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var destinations = ToursAgencyDataFuncs.GetAllDestinations();
            this.gridViewDestinations.DataSource = destinations;
            this.gridViewDestinations.DataBind();
            Session["destinations"] = destinations;
        }

        protected void gridViewDestinations_PageIndexChanged(object sender, GridViewPageEventArgs e)
        {
            this.gridViewDestinations.PageIndex = e.NewPageIndex;
            this.gridViewDestinations.DataSource = Session["destinations"];
            this.gridViewDestinations.DataBind();
        }

        protected string EncodeDestinationName(string property)
        {
            string name = (string)Eval(property);
            string encodedName = Server.HtmlEncode(name);
            return encodedName;
        }

        protected void DeleteDestination(object sender, CommandEventArgs e)
        {
            int id = int.Parse(e.CommandArgument.ToString());
            ToursAgencyDAL.Destination d = new ToursAgencyDAL.Destination();
            d.ID = id;
            ToursAgencyDataFuncs.DeleteDestination(d);
            var destinations = ToursAgencyDataFuncs.GetAllDestinations();
            this.gridViewDestinations.DataSource = destinations;
            this.gridViewDestinations.DataBind();
            Session["destinations"] = destinations;
        }

        protected void EditDestination(object sender, CommandEventArgs e)
        {
            Session["editDestination"] = int.Parse(e.CommandArgument.ToString());
            Response.Redirect("~/Admin/Modify/EditDestination.aspx");
        }
    }
}